package com.qqtech.qquan.pub.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.pub.model.PubUpgrade;
import com.qqtech.qquan.pub.model.PubUpgradeQuery;
import com.qqtech.qquan.pub.model.PubUpgradeVo;
import com.qqtech.qquan.pub.service.PubUpgradeService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/pub/upgrade")
public class PubUpgradeController extends BaseWebController<PubUpgrade, PubUpgradeQuery> {
	@Resource
	private PubUpgradeService pubUpgradeService;

	@Override
	protected BaseService<PubUpgrade> getBaseService() {
		return pubUpgradeService;
	}

	@RequestMapping(value = "/get")
	@ResponseBody
	public Result get(@RequestBody Map<String, String> map) {
		Result result = new Result();
		PubUpgradeVo upgradeVO = pubUpgradeService.getUpgradeByPlatform(new Integer(map.get("platform")));
		result.put("upgradeVO", upgradeVO);
		return result;
	}

	/**
	 * 根据客户端(内容)版本号获取对应的升级内容
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/getByVersion")
	@ResponseBody
	public Result getByVersion(@RequestBody Map<String, String> map) {
		Result result = new Result();
		PubUpgradeVo upgradeVO = pubUpgradeService.getUpgradeByPlatform(new Integer(map.get("platform")));
		result.put("upgradeVO", upgradeVO);
		return result;
	}

	@RequestMapping(value = "/checkUpgrade")
	@ResponseBody
	public Result checkUpgrade(@RequestBody Map<String, String> map) {
		return pubUpgradeService.checkUpgrade(map.get("contentVer"), map.get("nativeVer"),
				new Integer(map.get("platform")));
	}
}
